<?php

class config{

	public static function update_config($sync=true){
		$r = db::select("select * from config");
		//dump($r);
		$sync && $var = array('int'=>time());
		foreach ($r as $key => $value) {
			$var[$value['varName']] = $value['varValue'];
			$GLOBALS['G'][$value['varName']] = $value['varValue'];
		}
		$var['http_host'] = $_SERVER['HTTP_HOST'];

		$data = '<?php return ';
		$data .= var_export($var, true);
		$data .= ';';
		if(!is_dir(DATA.'/cache')){
			mkdir(DATA.'/cache');
		}
		
		if(file_put_contents(DATA.'/cache/config_cache.inc.php', $data)) {
			$respond = array('status'=>1, 'msg'=>'更新成功');
		} else {
			$respond = array('status'=>0, 'msg'=>'更新失败');
		}
		return $respond;
	}

}

